package com.mrgood.config;

import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;
import java.util.Enumeration;

public class CommonTool {
    public static String getHeader() {
        ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder
                .getRequestAttributes();
        if (attributes == null) {
            return "no attributes";
        }
        HttpServletRequest request = attributes.getRequest();
        Enumeration<String> headerNames = request.getHeaderNames();
        StringBuilder sb = new StringBuilder();
        sb.append("\r\n<br>");

        while (headerNames.hasMoreElements()) {
            String s = headerNames.nextElement();
            sb.append(s);
            sb.append(":");
            sb.append(request.getHeader(s));
            sb.append("\r\n<br>");
        }
        return sb.toString();
    }
}
